﻿@model IEnumerable<DNA.Mvc.WebPage>
@{
    var context = WebSiteContext.Current;
    var web = context.Web;
    }
<style type="text/css">
    #WebPageList .d-list-item-hover, #WebPageList .d-list-item-selected { background-color: #ffffff; }
</style>
@if (Model.Count() > 0)
{
    Ajax.DnaFor().ListBox(Model)
        .HtmlAttributes(new {style="overflow:visible;border:none;width:auto;height:auto;"})
        .DataValueField(m => m.ID)
        .ItemTemplate(page =>
        {
            Ajax.Dna().CollapsablePanel("PagePanel" + page.ID.ToString())
                       .Header(@<text>
    @{
        var icon = "icon_aspx_16.png";
        if (!page.ShowInMenu) { icon = "icon_hide_aspx_16.png"; }
        if (!page.AllowAnonymous) { icon = "icon_security_aspx_16.png"; }
        var _iconUrl = Url.Content("~/content/images/" + icon);
    }
    <div style="clear: left; padding: 5px; margin: 5px 5px 0px 0px;">
        <img src="@_iconUrl" class="d-icon" alt="" style="vertical-align:top;margin-right:3px; " /><span>@GE.GetContent(page.Title)</span>
    </div>
    </text>)
                       .Expand(false)
                       .Load(Url.Action("PageDetail", "DynamicUI", new { Area = "", website = web.Name, id = page.ID }))
                       .ImageUrl(Url.Content("~/content/images/icon_aspx_16.png"))
                       .Render();
        })
      .HtmlAttributes(new { style = "width:auto;height:500px;padding:10px;" })
      .Options(opts =>
      {
          var _parentID = ViewData["Page"] != null ? ((DNA.Mvc.WebPage)ViewData["Page"]).ID : 0;
          opts.IsSortable = true;
          opts.OnPositionChanged = "$.post(\"" + Url.Action("Move", "DynamicUI", new { Area = "", website = web.Name }) + "\",{parentID:" + _parentID.ToString() + ",id:$(\">input[type='hidden']\",ui.item).val(),pos:ui.index});";
      })
      .Name("WebPageList")
      .Render();
                   
    @Html.StartupScripts() 
}
else
{ 
    <div style="padding: 20px;">
        @{
    var _selectedPage = (DNA.Mvc.WebPage)ViewData["Page"];
    if (_selectedPage != null)
    {
        Ajax.Dna().CollapsablePanel()
           .Stick()
           .Title(GE.GetContent(_selectedPage.Title))
           .ImageUrl(Url.Content(_selectedPage.ShowInMenu ? "~/content/images/icon_aspx_16.png" : "~/content/images/icon_hide_aspx_16.png"))
           .Body(() =>
           {
               Html.RenderAction("PageDetail", "DynamicUI", new { Area = "", website = web.Name, id = _selectedPage.ID });
           })
           .Render();
    }
    else
    {
        Ajax.Dna().CollapsablePanel()
              .Stick()
              .Title(Html.Global("SubPages_MessageText"))
              .ImageUrl(Url.Content("~/content/images/icon_info_24.png"))
              .Body(@<text>
            <p style="padding: 20px;">
                <span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                <strong>@Html.Global("SubPages_MessageText"):</strong>@Html.Global("SubPages_MessageContent")</p>
            </text>)
             .Render();
    }
        }
    </div>
}